/**
 * Created by nengjian on 2017/5/15.
 */
'use strict';
var utils = require('../utils'),
    pipeline = require('../../utils/pipeline'),

    docName = 'users',
    allowedIncludes = ['count.posts', 'permissions', 'roles', 'roles.permissions'];

module.exports = app => {
    class datebase extends app.Service {
        * findAll(options) {
            var tasks;
            function doQuery(options) {
                return app.mysql.query("select table_name from information_schema.tables where table_schema='wxing-ghost' and table_type='base table'");
            }

            tasks = [
                doQuery
            ];
            return pipeline(tasks, options).then(function formatResponse(result) {
                if (result) {
                    return {datebase: result};
                }
            })
        }
        * findFields(_tablename) {
            function doQuery(_tablename) {
                return app.mysql.query("select COLUMN_NAME from information_schema.COLUMNS where table_name='"+_tablename+"' and table_schema='wxing-ghost'");
            }
            return pipeline([doQuery], _tablename).then(function formatResponse(result) {
                if (result) {
                    return result;
                }
            })
        }
    }
    return datebase;
};
